package com.wu.store.dao;

import com.wu.store.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.lang.Integer;

@Repository
public interface UserDao {
	User getUserByUserName(String username);

	User getUserByUid(Long uid);

	List<User> selectByKeyword(int isAvailable, String keyword);

	@Insert("<script>" +
		        "INSERT INTO t_user " +
		        "(username, password, gender, birthday, email, phone, province, city, area, address, is_available, role, create_time, source, auth_id, avatar, user_info)" +
		        " VALUES " +
		        "(#{username}, #{password}, #{gender}, #{birthday}, #{email}, #{phone}, #{province}, #{city}, #{area}, #{address}, #{isAvailable}, #{role}, #{createTime}, #{source}, #{authId}, #{avatar}, #{userInfo})" +
		        "</script>")
	Integer addUser(User user);

	@Update("<script>" +
		        "UPDATE t_user SET " +
		        " username=#{username}, " +
		        "password=#{password}, " +
		        "gender=#{gender}, " +
		        "birthday=#{birthday}, " +
		        "email=#{email}, " +
		        "phone=#{phone}, " +
		        "province = #{province}, " +
		        "city = #{city}, " +
		        "area = #{area}, " +
		        "address = #{address}, " +
		        "is_available=#{isAvailable}, " +
		        "role=#{role}, " +
		        "update_time=#{updateTime} " +
		        "<if test='avatar != null'>" +
		        " , avatar = #{avatar}" +
		        "</if>" +
		        "where id=#{id}" +
		        "</script>")
	void updateUser(User user);

	List<User> getUserList();

	void updatePassword(String password, String username);

	@Select("select * from t_user where source = #{source} and auth_id = #{authId}")
	User selectByAuthId(String source,String authId);
}
